<!DOCTYPE html>
<html class="x-admin-sm">
  {include file="Admin/Public/head" title="文章列表" /}
  
    <body>
        <div class="x-nav">
            <span class="layui-breadcrumb">
                <a">首页</a>
                <a>文章管理</a>
                <a><cite>文章列表</cite></a>
            </span>
            <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
                <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
            </a>
        </div>
        <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="layui-card-body ">
                            <form class="layui-form layui-col-space5">
                                <div class="layui-input-inline layui-show-xs-block">
                                  <input class="layui-input" placeholder="标题" name="name" value="{$param['name']}">
                                </div>
                                <div class="layui-input-inline layui-show-xs-block">
                                  <select name="parent_id" lay-search>
                                    <option value="">父级分类</option>
                                    {volist name="navs" id="val"}
                                    <option value="{$val['id']}" {if $param['parent_id'] == $val['id']}selected{/if}>{$val['name']}</option>
                                    {/volist}
                                  </select>
                                </div>
                                <div class="layui-input-inline layui-show-xs-block">
                                  <input class="layui-input" readonly placeholder="开始日" name="stime" id="start">
                                </div>
                                <div class="layui-input-inline layui-show-xs-block">
                                  <input class="layui-input" readonly placeholder="截止日" name="etime" id="end">
                                </div>
                                <div class="layui-input-inline layui-show-xs-block">
                                  <select name="display">
                                    <option value="">是否显示</option>
                                    <option value="0" {if $param['display'] == '0'}selected{/if}>显示</option>
                                    <option value="1" {if $param['display'] == 1}selected{/if}>隐藏</option>
                                  </select>
                                </div>
                                <div class="layui-input-inline layui-show-xs-block">
                                  <button class="layui-btn"  lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
                                </div>
                            </form>
                        </div>
                        <div class="layui-card-header">
                            <button class="layui-btn layui-btn-danger" onclick="delAll()">
                                <i class="layui-icon"></i>批量删除</button>
                            <button class="layui-btn" onclick="xadmin.open('富文本','/admin/article/info.html?id=', '', '', true)">
                                <i class="layui-icon"></i>富文本</button>
                            <button class="layui-btn" onclick="xadmin.open('markdown','/admin/article/info.html?id=&contentType=1', '', '', true)">
                                <i class="layui-icon"></i>markdown</button>
                        </div>
                        <div class="layui-card-body ">
                            <table class="layui-table layui-form">
                              <thead>
                                <tr>
                                  <th width="20">
                                    <input type="checkbox" class="checkFather" lay-skin="primary" lay-filter="allChoose">
                                  </th>
                                  <th width="70">ID</th>
                                  <th>标题</th>
                                  <th width="50">分类</th>
                                  <th width="80">更新时间</th>
                                  <th width="80">阅读数</th>
                                  <th width="80">是否显示</th>
                                  <th width="250">操作</th>
                              </thead>
                              <tbody class="x-cate">
                                {volist name="data['datas']" id="val" key="i"}
                                  <tr>
                                    <td>
                                      <input type="checkbox" class="checkChild" value="{$val['id']}" lay-skin="primary" lay-filter="itemChoose">
                                    </td>
                                    <td>{$val['id']}</td>
                                    <td>{$val['name']}</td>
                                    <td>{$val['nav_name']}</td>
                                    <td>{$val['update_time']}</td>
                                    <td>{$val['read_number']}</td>
                                    <td>
                                      <input type="checkbox" lay-text="显示|隐藏" {if $val['display'] == 0} checked {/if} lay-skin="switch"  lay-filter="display">
                                    </td>
                                    <td class="td-manage">
                                        {if $val['content_type'] == '0'}
                                            <button class="layui-btn layui-btn layui-btn-xs" onclick="xadmin.open('富文本','/admin/article/info.html?id={$val['id']}', '', '', true)" ><i class="layui-icon">&#xe642;</i>富文本</button>
                                        {elseif $val['content_type'] == '1'}
                                            <button class="layui-btn layui-btn layui-btn-xs" onclick="xadmin.open('markdown','/admin/article/info.html?id={$val['id']}&contentType=1', '', '', true)" ><i class="layui-icon">&#xe642;</i>markdown</button>
                                        {/if}
                                      <a href="/articles/{$val['id']}.html" target="_blank"><button class="layui-btn layui-btn layui-btn-xs layui-bg-blue"><i class="layui-icon">&#xe705;</i>查看</button>
                                      </a>
                                    </td>
                                  </tr>
                                {/volist}
                              </tbody>
                            </table>
                        </div>
                        <div class="layui-card-body ">
                            <div class="page">
                                <div>
                                  {include file="Admin/Public/page" /}
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        {include file="Admin/Public/checkAll" /}
        <script>
          layui.use(['form', 'laydate'], function(){
            let form = layui.form;
            var laydate = layui.laydate;

            laydate.render({
                elem: '#start',
                trigger: 'click',
            });

            laydate.render({
                elem: '#end',
                trigger: 'click',
            });
            form.on('switch(display)', function(data){
              let display = this.checked ? 0 : 1,
                id = $(data.othis[0]).parents("tr").find(".checkChild").val()

              layer.load(2);
              $.post("/admin/article/display", {display: display,id: id}, function(data){
                layer.closeAll();
              });
            });
            checkAll(form);
          });
          $("#go").click(function(){
            let page = $("#goPage").val();
            if (page > 0 && page <= Number($(".num:last").text())) {
              location.href="{$url}?page="+page+"&{$data['query']|raw}"
            }
          })

          function delAll () {
            let ids = getCheckValues();
            layer.confirm('确认要删除吗？', function(index){
              layer.load(2);
              $.post("/admin/article/delete", {id: ids}, function(data){
                layer.closeAll();
                if (data.code == 200) {
                  layer.msg(data.msg, {time: 1500}, function(){
                    location.reload();
                  })
                } else if (data.code) {
                  layer.msg(data.msg)
                }
              })
            });
          }
        </script>
    </body>
</html>